---
title: Configuration.replaceMessageBody()
api: Configuration.replaceMessageBody
---

## Description

<Summary/>

<FilterDiagram
  name="replaceMessageBody"
  input="Event"
  output="Event"
/>

The user function will receive as parameter a [Data](/reference/api/Data) object that contains a full message body and is removed from the input stream. Whatever the function returns will be inserted into the output stream in place of the removed events. It can be an event or a [Message](/reference/api/Message), or an array of events or _Messages_. If the function returns nothing (_null_ or _undefined_), no events will be inserted back into the stream.

This filter only calls the user function once for each message in the input stream. If the message's body is composed of multiple _Data_ events, **replaceMessageBody** will wait until all _Data_ objects composing the whole message are collected and call the user function with a combined _Data_ event.

You can also use a fixed replacement value instead of a function if the replacement is static.

## Syntax

``` js
pipy()
  .pipeline()
  .replaceMessageBody(
    data => transform(data)
  )
```

## Parameters

<Parameters/>

## See Also

* [Configuration](/reference/api/Configuration)
* [replaceStreamStart()](/reference/api/Configuration/replaceStreamStart)
* [replaceStreamEnd()](/reference/api/Configuration/replaceStreamEnd)
* [replaceMessageStart()](/reference/api/Configuration/replaceMessageStart)
* [replaceMessageEnd()](/reference/api/Configuration/replaceMessageEnd)
* [replaceMessage()](/reference/api/Configuration/replaceMessage)
* [replaceData()](/reference/api/Configuration/replaceData)
